package mysql

import (
	"bluebell/models"
	"database/sql"
	"go.uber.org/zap"
)

func GetCommunityList() (communityList []*models.Community, err error) {
	sqlStr := "select community_id, community_name from community"
	err = db.Select(&communityList, sqlStr)
	if err != nil {
		if err == sql.ErrNoRows {
			zap.L().Warn("数据库社区为空")
			err = nil

		}
		return
	}

	return
}

// 根据ID 查找社区
func GetCommunityDetail(id int64) (data *models.CommunityDetail, err error) {
	sqlStr := "select community_id, community_name, introduction, create_time from community where community_id = ?"
	data = new(models.CommunityDetail)
	err = db.Get(data, sqlStr, id)
	if err != nil {
		if err == sql.ErrNoRows {
			zap.L().Warn("未查询到此社区")
			err = ErrInvalidID

		}
		return
	}

	return

}
